﻿// See https://aka.ms/new-console-template for more information
 int counter = 0;
 Object lockobject= new Object();
Thread[] threads=new Thread[5];
for (int i = 0; i < threads.Length; i++)
{
    threads[i] = new Thread(() => {
        for (int j = 0; j < 1000; j++)
        {
           // lock (lockobject)
           // { 
            counter++;
           // }
         //   Thread.Sleep(10);
            Console.WriteLine($"线程{Thread.CurrentThread.ManagedThreadId}，计数值{counter}");
        }
        });
    threads[i].Start();
}
threads.ToList().ForEach(t=>t.Join());
Console.WriteLine($"最终计数值为：{counter}");
Console.ReadKey();
